package com.yuyu.commons.toolKit;

import java.util.ArrayList;
import java.util.List;

/**
 * @author
 * @version 1.0
 * @description: 类型转换
 * @date 2022/11/23 13:40
 */
public class CastUtil {


    /**
     * object -> list
     * @param obj
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> List<T> castList(Object obj, Class<T> clazz) {
        List<T> result = new ArrayList<T>();
        if(obj instanceof List<?>) {
            for (Object o : (List<?>) obj) {
                result.add(clazz.cast(o));
            }
            return result;
        }
        return null;
    }
}
